/**
 * @param {string} msg 提示语内容
 */
function dmAlert(msg,option){
	
	var option = option == undefined ? option = {} : option ;
	option.type == undefined ? option.type = 0 : option.type;
	option.enter == undefined ? option.enter='确定' : option.enter;
	option.cancel == undefined ? option.cancel='取消' : option.cancel;
	
	$("body").append(`
		<div id="mask">
			<div class="dm-mask"></div>
			<div class="dm-msg">
				<h4 class="txt">${msg}</h4>
				<ul class="top-line h5 btn-box flex-row">
					${option.type != 1?`<li class="flex-full cancel">${option.cancel}</li>`:''}
					<li class="flex-full left-line enter">${option.enter}</li>
				</ul>
			</div>
		</div>
	`);
	//关闭
	function closeMask(){
		$("#mask").hide(0,function(){
			$("#mask").remove();
		});
	};
	
	$("#mask .dm-msg .cancel").click(function(){
		closeMask();
		if(typeof option.fail == 'function'){
			option.fail();
		};
	});
	
	//确定
	$("#mask .dm-msg .enter").click(function(){
		if(typeof option.success == 'function'){
			option.success();
		};
		closeMask();
	});
	
};


function tip(content,callback){
	
	//获取当前tip数量
	var len = $('.dm-tip').length;
	
	$("body").append(`
		<div class="dm-tip">${content}</div>	
	`);
	
	if(len > 1){
		$('.dm-tip').each(function(i){
			if(i<len-1){
				$(this).fadeOut(function(){
					$(this).remove();
				});
			}else{
				closeTip($(this));
			};
		});
	}else{
		closeTip($('.dm-tip'));
	};
	
	function closeTip(obj){
		obj.animate({'margin-top':'0','opacity':'1'},500,function(){
			setTimeout(function(){
				obj.remove();
				if(typeof callback == 'function'){
					callback();
				};
			},800);
		});
	};
};




//选择模组
function dmSelect(arr,callback){
	var list = '';
	for(i in arr){
		list += `<li class="top-line" data-index="${i}">${arr[i]}</li>`;
	};
	
	$("body").append(`
		<div id="dmSelectMod">
			<div class="dm-mask"></div>
			<div class="dm-selMod">
				<ul>${list}</ul>
				<a class="cancel">取消</a>
			</div>	
		</div>	
	`);
	
	$("#dmSelectMod .dm-selMod").animate({'bottom':0});
	
	//取消
	$("#dmSelectMod .cancel,#dmSelectMod .dm-mask").click(function(){
		$("#dmSelectMod .dm-mask").fadeOut();
		$("#dmSelectMod .dm-selMod").animate({'bottom':'-100%'},function(){
			$("#dmSelectMod").remove();
		});
	});
	
	//选择
	$("#dmSelectMod ul li").click(function(e){
		$("#dmSelectMod .dm-mask").fadeOut();
		$("#dmSelectMod .dm-selMod").animate({'bottom':'-100%'},function(){
			$("#dmSelectMod").remove();
		});
		
		var index = e.currentTarget.getAttribute('data-index');
		if(typeof callback == 'function'){
			callback(index);
		};
	});
};




//案例单项筛选
function caseRadio(arr,check=0,callback){
	$("#screenMask").remove();
	var html = '';
	for(i in arr){
		if(i == check){
			html += `<span class="bottom-line on" data-check="${i}">${arr[i]}</span>`;
		}else{
			html += `<span class="bottom-line" data-check="${i}">${arr[i]}</span>`;
		};
	};
	$('body').append(`
		<div id="screenMask">
			<div class="screenMask"></div>
			<div class="singleScreen">
				${html}
			</div>
		<div>
	`);
	
	$("#screenMask .singleScreen").on('click','span',function(){
		if(typeof callback == 'function'){
			callback($(this).attr('data-check'));
		};
		$("#screenMask").hide(function(){
			$("#screenMask").remove();
		});
	});
	
};



//新增手机号
function dmComfirm(title='提示消息',option){
	
	var option = option == undefined ? option = {} : option ;
	option.type == undefined ? option.type = 0 : option.type;
	option.text == undefined ? option.text='' : option.text ;
	option.enter == undefined ? option.enter='确定' : option.enter;
	option.cancel == undefined ? option.cancel='取消' : option.cancel;
	
	$("body").append(`
		<div id="mask">
			<div class="dm-mask"></div>
			<div class="dm-msg">
				<h4 class="bt">${title}</h4>
				<div class="txt">
					<input type="tel" id="inputNode" maxlength="11" value="${option.text}" placeholder="请输入新手机号" />
				</div>
				<ul class="top-line h5 btn-box flex-row">
					${option.type !== 1?`<li class="flex-full cancel">${option.cancel}</li>`:''}
					<li class="flex-full left-line enter">${option.enter}</li>
				</ul>
			</div>
		</div>
	`);
	//关闭
	function closeMask(){
		$("#mask").hide(0,function(){
			$("#mask").remove();
		});
	};
	
	$("#mask .dm-msg .cancel").click(function(){
		closeMask();
	});
	
	//确定
	$("#mask .dm-msg .enter").click(function(){
		var val = $("#mask #inputNode").val();
		if(typeof option.success == 'function' && val != ''){
			closeMask();
			setTimeout(function(){
				option.success(val);
			},20);
		};
	});
	
};